package contact.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import contact.domain.Contact;
import contact.domain.DAOContact;


public class RemoveContact extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private DAOContact daoContact;
    
    public RemoveContact(DAOContact dc){
    	this.daoContact = dc;
    }
	
	
	public RemoveContact() {
		super();
		daoContact = new DAOContact();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try{
			Long id = new Long(request.getParameter("id"));
			Contact contact = daoContact.read(id);
			daoContact.delete(contact);
		}
		catch(NumberFormatException e){}
		RequestDispatcher rd = request.getRequestDispatcher("/removeContact.jsp");
		rd.forward(request, response);

	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

	}

}
